xy_p_palm <- function (fil='xy.txt', nam='name') {
xy=read.csv(fil, header=F)
xy1=as.vector(xy, mode='numeric')
len=length(xy1)

#先确定自然原点，即坐标最小的点，然后转换为 zeiss坐标 和 1原点坐标
# 目标区域 15mm
width=15

# 1自然原点
x0=94
y0=44

x0=96
y0=18

# 2自然原点
x0=96

# ni-v
y0=17.5

# 50i
# y0=16

# 3 自然原点




# zeiss 坐标系
 ##############
 #            #
 #            #  
#4############3
 # x--->      #   
 #y           #
 #|           #
 #|           #
 #\/          #
 #            #
#1############2

# x1_zeiss=-142.7
# y1_zeiss=-15.3

# x4_zeiss=x1_zeiss
# y4_zeiss=y1_zeiss-width

x4_zeiss=-142.7
y4_zeiss=-30.3

# x4_zeiss=-143
# y4_zeiss=-31.4





#判断 xy 轴，并计算自然原点下的坐标
if (xy1[1] < 70) {
y=xy1[seq(1,len,2)]-y0
x=xy1[seq(2,len,2)]-x0
}else {
x=xy1[seq(1,len,2)]-x0
y=xy1[seq(2,len,2)]-y0
}


# 2原点转换为4原点，zeiss
x4_0=width-x
y4_0=width-y


# 1原点转换为4原点，zeiss
# x4_0=x
# y4_0=width-y

# 4转换为相对于位点1，用于画图，因为画图的原点是位点1
x1=x4_0
y1=width-y4_0


# 转换为zeiss 坐标
trans=1000
x_zeiss=(x4_zeiss + x4_0)* trans
y_zeiss=(y4_zeiss + y4_0)* trans



xy_d=data.frame(x_zeiss,y_zeiss)

out_name=paste(nam, 'xys.txt', sep='.');
write.table(xy_d, out_name, sep='\t', quote=F)


xlim=c(-2,17)
lin=seq(xlim[1]+1, xlim[2]-1)

plot(NA, type='n', xlim=xlim, ylim=xlim, cex.axis=.5)
abline(h=lin, v=lin, col='gray')
lines(c(0, 15, 15, 0, 0), c(0, 0, 15, 15, 0))
points(x1, y1, xlim=xlim, ylim=xlim, asp=1, pch=16)
lenx=length(x)
text(x1, y1, 1:lenx, pos=4)
title(nam)

}



# plot (0 ,main = paste(strwrap("This is a really long title that
# i can not type it properly",width = 50 ) ,
# collapse = "\n"))